<cfcomponent output="false">

	<cffunction name="validateData" access="public" returntype="Any">
		<cfargument name="data" required="true" type="String">
		<cfargument name="inputData" required="true" type="String">
		
		<cftry>
				<cfswitch expression="#arguments.inputData#">
				
					<cfdefaultcase><!--- XML --->
						<cfset arguments.data = XmlParse(arguments.data)>						
					</cfdefaultcase>
				</cfswitch>
			
			<cfcatch type="any">
				<cfdump var="#cfcatch#">
				<cfthrow 
					errorcode="#cfcatch.ErrorCode#" 
					message="#cfcatch.Message#" 
					type="#cfcatch.Type#" 
					extendedinfo="#cfcatch.ExtendedInfo#"  
					detail="#cfcatch.Detail#">
			</cfcatch>
		</cftry>
		
		
	</cffunction>
	
	<cffunction name="validateXMLData" access="private" returntype="xml">
		<cfargument name="data" required="true" type="String">
		<!---
		@todo:	validar data
		 --->
	</cffunction>
	
	<cffunction name="validateJSONData" access="private" returntype="xml">
		<cfargument name="data" required="true" type="String">
		<!---
		@todo:	validar data
		 --->
	</cffunction>
	
	<cffunction name="validateRequest" access="public" returntype="struct">
		<cfargument name="dataRequest" type="struct" required="true">
		<cftry>
			
				<!---
					validate the require fields
					name="module" type="string"
					name="action" type="string"
					name="data" type="Any"
					name="username" type="string"
					name="password" type="string"
					name="typeData" type="string"
					name="returnType" type="string"
				--->
				
				<cfif not StructKeyExists(arguments.dataRequest,'module')>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_MODULE_NOEXIST" 
						message="MANAGER_VALIDREQUEST_MODULE_NOEXIST" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_MODULE_NOEXIST" 
						detail="MANAGER_VALIDREQUEST_MODULE">
				</cfif>
				
				<cfif trim(arguments.dataRequest.module) eq ''>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_MODULE" 
						message="MANAGER_VALIDREQUEST_MODULE" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_MODULE" 
						detail="MANAGER_VALIDREQUEST_MODULE">
				</cfif>
				
				
				<cfif not StructKeyExists(arguments.dataRequest,'action')>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_ACTION" 
						message="MANAGER_VALIDREQUEST_ACTION" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_ACTION" 
						detail="MANAGER_VALIDREQUEST_ACTION">
				</cfif>
				
				<cfif not StructKeyExists(arguments.dataRequest,'data')>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_DATA" 
						message="MANAGER_VALIDREQUEST_DATA" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_DATA" 
						detail="MANAGER_VALIDREQUEST_DATA">
				</cfif>
				
				<cfif not StructKeyExists(arguments.dataRequest,'username')>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_USERNAME" 
						message="MANAGER_VALIDREQUEST_USERNAME" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_USERNAME" 
						detail="MANAGER_VALIDREQUEST_USERNAME">
				</cfif>
				
				<cfif not StructKeyExists(arguments.dataRequest,'password')>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_PASSWORD" 
						message="MANAGER_VALIDREQUEST_PASSWORD" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_PASSWORD" 
						detail="MANAGER_VALIDREQUEST_PASSWORD">
				</cfif>
				
				<cfif not StructKeyExists(arguments.dataRequest,'inputData')>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_INPUTDATA" 
						message="MANAGER_VALIDREQUEST_INPUTDATA" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_INPUTDATA" 
						detail="MANAGER_VALIDREQUEST_INPUTDATA">
				</cfif>
				
				<cfif not StructKeyExists(arguments.dataRequest,'outputData')>
					<cfthrow 
						errorcode="MANAGER_VALIDREQUEST_OUTPUTDATA" 
						message="MANAGER_VALIDREQUEST_OUTPUTDATA" 
						type="Application" 
						extendedinfo="MANAGER_VALIDREQUEST_OUTPUTDATA" 
						detail="MANAGER_VALIDREQUEST_OUTPUTDATA">
				</cfif>
				<cfset managerBusiness = this.callComponent('ManagerBusiness')>
				<cfset arguments = managerBusiness.setDefaultData(#arguments.dataRequest#)>
				<cfset arguments.data = this.validateData(#arguments.data#,#arguments.inputData#)>
				
				
			<cfcatch type="any">
				<cfdump var="#cfcatch#">
				<cfthrow 
					errorcode="#cfcatch.ErrorCode#" 
					message="#cfcatch.Message#" 
					type="#cfcatch.Type#" 
					extendedinfo="#cfcatch.ExtendedInfo#"  
					detail="#cfcatch.Detail#">
			</cfcatch>
		</cftry>
		
		<cfreturn arguments>
	</cffunction>
	
	<cffunction name="callComponent" access="public" returntype="any">
		<cfargument name="componentName" type="string" required="true">
		<cfset var.component = false>
		<cfset var.tmpLogicalPath = ''>
		<cftry>
			<cfif not StructKeyExists(application,'constants')>
				<cfthrow 
						errorcode="MANAGERCONTROLLER_CALLCOMPONENT_CONSTANTS" 
						message="MANAGERCONTROLLER_CALLCOMPONENT_CONSTANTS" 
						type="Application" 
						extendedinfo="MANAGERCONTROLLER_CALLCOMPONENT_CONSTANTS" 
						detail="MANAGERCONTROLLER_CALLCOMPONENT_CONSTANTS">
				
			</cfif>
			<!--- Controller --->
			<cfif findnocase('controller',arguments.componentName)>
				<cfset var.tmpLogicalPath = application.constants.CONTROLLER_PATH & '.' & arguments.componentName>
				<cfset var.component = createObject('component',var.tmpLogicalPath)>
			</cfif>
			
			<!--- Business --->
			<cfif findnocase('business',arguments.componentName)>
				<cfset var.tmpLogicalPath = application.constants.BUSINESS_PATH & '.' & arguments.componentName>
				<cfset var.component = createObject('component',var.tmpLogicalPath)>
			</cfif>
			
			<!--- DAO --->
			<cfif findnocase('dao',arguments.componentName) && trim(var.tmpLogicalPath) eq ''>
				<cfset var.tmpLogicalPath = application.constants.DAO_PATH & '.' & arguments.componentName>
				<cfset var.component = createObject('component',var.tmpLogicalPath)>
			</cfif>
			
			<!--- GATEWAY --->
			<cfif findnocase('gateway',arguments.componentName) && trim(var.tmpLogicalPath) eq ''>
				<cfset var.tmpLogicalPath = application.constants.DAO_PATH & '.' & arguments.componentName>
				<cfset var.component = createObject('component',var.tmpLogicalPath)>
			</cfif>
			
			
			<cfcatch type="any">
				<cfthrow 
					errorcode="#cfcatch.ErrorCode#" 
					message="#cfcatch.Message#" 
					type="#cfcatch.Type#"  
					detail="#cfcatch.Detail#">
			</cfcatch>
		</cftry>
		<cfreturn var.component>
	</cffunction>
	
	
</cfcomponent>